<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DBManager
 *
 * @author G011C1102
 */
class DBManager {

	public static $db;

	public static function init() {
		DBManager::$db = null;
//		DBManager::$db = new PDO('mysql:host=localhost;dbname=social_album;charset=utf8', 'phpusr', 'phppass', array(PDO::ATTR_PERSISTENT => true));
		DBManager::$db = new PDO('mysql:host=localhost;dbname=group10db;charset=utf8', 'group10', 'group10', array(PDO::ATTR_PERSISTENT => true));
	}
	
	public function registerUser($account_id, $mail, $pass){
		// $pass = $pass 暗号化
		$sec = new Security();
		$array = $sec ->salt_protection($pass, $mail);
		
		$db = DBManager::$db;
		$stt = $db->prepare('INSERT INTO user (account_id, mail,  password, salt) VALUES (:name, :mail, :pass, :salt)');
		$stt->bindValue(':name', $account_id);
		$stt->bindValue(':mail', $array['mail']);
		$stt->bindValue(':pass', $array['hash']);
		$stt->bindValue(':salt', $array['salt']);

		return $stt->execute();
	}
	
	public function updataUser($name, $mail, $pass){
		// $pass = $pass 暗号化
		
		$db = DBManager::$db;
		$stt = $db->prepare("UPDATE user SET mail = :mail, password = :pass WHERE account_id = :name");
		$stt->bindValue(':name', $name);
		$stt->bindValue(':mail', $mail);
		$stt->bindValue(':pass', $pass);
		$stt->execute();	
	}
	
	public function registerAlbum($name, $a){
		
		$db = DBManager::$db;
		$stt = $db->prepare('INSERT INTO user (name, password) VALUES(:name, :pass)');
		$stt->bindValue(':name', $name);
		$stt->bindValue(':pass', $pass);
		$stt->execute();	
	}

}

?>
